home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 3
/
Info_Mac_1994-01.iso
/
Graphics
/
Utility
/
GL Viewer 1.1.1
/
src ƒ
/
glview.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-06
|
7KB
|
325 lines
/*-
* glview.c - main routines for grasp viewer.
*
* Macintosh version of GL Viewer, compiler: THINK C 5.0.x
*
* from XGRASP, Copyright (c) 1991 by Patrick J. Naughton
* 1993 THINK C 5.0.x version by Martin Fong (mwfong@nisc.sri.com)
*
*/
#pragma segment GLView
#define DEBUG 1
#define Version "1.1.1, 06-Sep-93"
#include <stdlib.h>
#include "glassert.h"
#include "grasp.h"
char *pname;
int imageloop = 0;
int showdirectory = 0;
int showtext = 0;
int printthecodes = 0;
int fQuiet = 0;
int verbose = 0;
int imverbose = 0;
Display *dsp;
Window win;
Visual *vis;
XVisualInfo vinfo;
int screen;
int planes;
GC gc;
GC gc1;
long whiteC;
long blackC;
//Atom protocol_atom;
//Atom kill_atom;
Bool aboutdone = False;
void about()
{
fprintf(stderr, "\n%s, version %s\n\n",pname,Version);
fprintf(stderr,
"This program tries to recreate the functionality provided by the PC\n"
"program GRASPRT.EXE. It plays animation files which usually have the\n"
"extension .GL. This file format is partially described by the\n"
"documents found in the file 'docs'. It has many missing features, but\n"
"it is complete enough to view a large percentage of the GL files.\n\n");
fprintf(stderr,
"The original Mac version was hacked from the X-Window source code,\n"
"XGRASP (v1.7), available at anonymous ftp sites or e-mail to\n"
"xgrasp@ankh.ftl.fl.us, and copyright (c) 1991 by Patrick J. Naughton.\n\n");
fprintf(stderr, "Command line interface: file.gl -debugopts\n");
fprintf(stderr, "usage: file.gl -all -verbose -dir -textout -images -imverbose -printcodes\n");
aboutdone = True;
}
char *
strdup(s)
char *s;
{
char *new = malloc((size_t) strlen(s) + 1);
return (new ? strcpy(new, s) : (char *) 0);
}
void
error(s1, s2)
char *s1, *s2;
{
if (!aboutdone) about();
fprintf(stderr, s1, pname, s2);
XExit(1);
}
void
outi(s, i)
char *s;
int i;
{
fprintf(stderr, "%s: %d\n", s, i);
}
void
outs(s1, s2)
char *s1, *s2;
{
fprintf(stderr, "%s: %s\n", s1, s2);
}
u_int
GetByte(fp)
FILE *fp;
{
return (u_int) getc(fp);
}
u_int
GetWord(fp)
FILE *fp;
{
u_int b1 = getc(fp);
u_int b2 = getc(fp);
return (u_int) (b1 + b2 * 256);
}
u_long
GetLong(fp)
FILE *fp;
{
u_long b1 = getc(fp);
u_long b2 = getc(fp);
u_long b3 = getc(fp);
u_long b4 = getc(fp);
u_long retVal = b1 + (b2 + (b3 + b4 * 256L) * 256L) * 256L;
return (retVal);
}
#define TOO_MANY_ENTRIES 256
FilenameStruct *
readdirectory(fp, count)
FILE *fp;
int *count;
{
FilenameStruct *fn;
int i;
int len = GetWord(fp);
long plen;
long numEntries;
numEntries = (len / 17) - 1;
*count = numEntries;
if (0 >= *count || *count > TOO_MANY_ENTRIES)
error ("%s: Not a GL archive (# entries = %ld)\n", (char *) numEntries);
fn = (FilenameStruct *) malloc((size_t) *count * sizeof(FilenameStruct));
assert (fn);
for (i = 0; i < *count; i++) {
fn[i].offset = GetLong(fp);
fread(fn[i].fname, 13, 1, fp);
fn[i].fname[13] = 0;
lowerstr(fn[i].fname);
}
if (showdirectory) {
fprintf(stderr, "%13s %6s %6s\n", "Name", "offset", "hexoff" );
for (i = 0; i < *count; i++) {
/* if (i+1 == *count) plen= -1 else plen= fn[i+1].offset - fn[i].offset; */
fprintf(stderr, "%13s %6ld %6lX\n", fn[i].fname, fn[i].offset, fn[i].offset);
}
}
return (fn);
}
usage()
{
error("Error: Bad usage.\n", NULL);
}
#ifdef DEBUG
/* command line reader for Mac/MPW -- dgg */
int readCmdOptions(FILE *cl, char ***argv)
{
#define MAXS 255
#define addarg(sptr) if (strlen(sptr)>0) { \
targv = (char **) realloc( targv, (argc+1) * sizeof(char *)); \
targv[argc] = (char *) malloc((size_t) 1+strlen(sptr) * sizeof(char)); \
assert (targv[argc]); \
strcpy( targv[argc], sptr); \
argc++; }
char *pword, st[MAXS];
const char *progname = "glview";
int argc = 0;
char **targv;
targv = NULL;
addarg( progname);
fgets( st, MAXS, cl);
if (!feof(cl) && st!=NULL && *st!=0) {
pword = strtok( st, "\ \n");
while (pword!=NULL) {
addarg( pword);
pword = strtok( NULL, "\ \n");
}
}
*argv = targv;
return argc;
}
int ccommand(char ***argv)
{
int argc;
char **targv;
argc = readCmdOptions(stdin, &targv);
*argv = targv;
return argc;
}
#endif DEBUG
real_main(argc, argv)
int argc;
char *argv[];
{
char *displayName = "GL View";
char *filename = 0;
FILE *fp;
FilenameStruct *dir;
int count;
int i;
OSType SFTypes[4];
//mac
SFTypes[0]='TEXT';
SFTypes[1]='BINA';
SFTypes[2]='GlVw';
SFTypes[3]='????';
filename = StdGetFile ((char *) "\pChoose GL File:", SFTypes, 4);
pname = "GL Viewer";
if (!filename) {
#ifdef DEBUG
about();
fprintf(stderr, "command> ");
argc= ccommand(&argv);
pname = argv[0];
for (i = 1; i < argc; i++) {
char *s = argv[i];
int n = strlen(s);
if (!strncmp("-dir", s, n))
showdirectory = 1;
else if (!strncmp("-textout", s, n))
showtext = 1;
else if (!strncmp("-images", s, n))
imageloop = 1;
else if (!strncmp("-verbose", s, n))
verbose = 1;
else if (!strncmp("-quiet", s, n))
fQuiet = 1;
else if (!strncmp("-imverbose", s, n))
imverbose = 1;
else if (!strncmp("-printcodes", s, n))
printthecodes = 1;
else if (!strncmp("-all", s, n)) {
showdirectory = 1;
showtext = 1;
imageloop = 1;
verbose = 1;
imverbose = 1;
printthecodes = 1;
}
else if (filename || s[0] == '-')
usage();
else
filename = s;
}
if (!filename) error("%s: No gl file selected.\n", NULL);
#else
error("%s: No gl file selected.\n");
#endif
}
{
CursHandle hWatchCursor = GetCursor (watchCursor);
if (hWatchCursor /* != (CursHandle) NULL */)
{
HLock ((Handle) hWatchCursor);
SetCursor (*hWatchCursor);
ReleaseResource (hWatchCursor);
}
}
displayName = filename;
if (!(dsp = XOpenDisplay(displayName)))
error("%s: unable to open display.\n", NULL );
fp = fopen(filename, "rb");
if (!fp) error("%s: %s not found.\n", filename);
if (verbose) fprintf(stderr, "\n readdirectory...\n");
dir = readdirectory(fp, &count);
if (verbose) fprintf(stderr, "\n readfiles...\n");
readfiles(fp, dir, count);
fclose(fp);
InitCursor ();
if (verbose) fprintf(stderr, "\n execfile...\n");
if (numexecs == 0)
error ("%s: no text script file found.\n", NULL);
execfile(execRec[0], 0);
XExit(0);
}